import random

import requests
from lxml import etree
from ddddocr import DdddOcr
ocr = DdddOcr(show_ad=False)


res_code = requests.get(f'https://www.labnetwork.com.cn/gateway/basic/mall/oauth/code?{random.random}')
code_data = res_code.json()
uuid = code_data['data']['uuid']
img = code_data['data']['img'][22:]

r = ocr.classification(img)
print(r)

login_post = requests.post('https://www.labnetwork.com.cn/gateway/basic/mall/oauth/login', json={
    "userEmail": "1741964482@qq.com",
    "password": "Dby1741964482",
    "captchaCode": f"{r}",
    "captchaKey": f"{uuid}"
})

token = login_post.json()['data']['userInfo']['token']


res_product = requests.get('https://www.labnetwork.com.cn/gateway/oldapi/mall/chemical/products',json={
    "query": "五/六元芳香环->三嗪",
    "country": "CN",
    "pageSize": 10,
    "chemIds": [],
    "suppliers": [],
    "rank": 0,
    "packSize": "",
    "packUnit": "",
    "unitStock": "",
    "selectedUnit": "",
    "molecularWeightLow": "",
    "molecularWeightHigh": "",
    "locations": [],
    "startRecord": 10,
    "modelRange": [
        127.1,
        270.72
    ]
}, headers={
    token: token
})

print(res_product.json())
